package com.blb.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

//@Aspect
//@EnableAspectJAutoProxy
//@Configuration
//public class TransactionAspect {
//
//    //注入事务管理器
//    @Autowired
//    private DataSourceTransactionManager transactionManager;
//
//    @Around("execution(* com.blb.sevice.Impl.*.update*(..))")
//    public Object transaction(ProceedingJoinPoint joinPoint) throws Throwable {
//        System.out.println("启动事务");
//        TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
//        //执行原方法
//        Object result = joinPoint.proceed();
//        transactionManager.commit(status);
//        System.out.println("事务提交");
//        return result;
//    }
//}
